package com.campus.service.Impl;

import com.campus.common.PageResult;
import com.campus.domain.Dto.ActivityCreateDto;
import com.campus.domain.Dto.ActivitySelectDto;
import com.campus.domain.Dto.ActivityUpdateDto;
import com.campus.domain.Vo.ActivityPageVo;
import com.campus.mapper.ActivityMapper;
import com.campus.service.IActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class ActivityServiceImpl implements IActivityService {

    @Autowired
    private ActivityMapper activityMapper;


    @Override
    public Integer addActivity(ActivityCreateDto activityCreateDto) {
        return activityMapper.addActivity(activityCreateDto);
    }

    @Override
    public Integer updateActivity(ActivityUpdateDto activityUpdateDto) {
        return activityMapper.updateActivity(activityUpdateDto);
    }

    @Override
    public Integer publish(Integer id) {
        return activityMapper.updateStatus(1,id);
    }

    @Override
    @Transactional
    public PageResult<ActivityPageVo> page(ActivitySelectDto activitySelectDto, Integer pageNum, Integer pageSize) {

        List<ActivityPageVo> list = activityMapper.page(activitySelectDto, pageNum, pageSize);
        Integer total = activityMapper.pageCount(activitySelectDto);
        return new PageResult<ActivityPageVo>().setData(list)
                .setPageNum(pageNum)
                .setPageSize(pageSize)
                .setTotal(total);
    }
}
